package kr.hkit.powerjava.chapter14.work;
import java.awt.BorderLayout;
import java.awt.EventQueue;

import javax.swing.JFrame;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.border.EmptyBorder;
import javax.swing.JButton;
import javax.swing.JTextField;

import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.FlowLayout;
public class Programmin01 extends JFrame implements ActionListener {
	private JPanel contentPane;
	private Programming01_panel panel;
	private JButton btnNewButton;
	private JTextField Result;
	public static void main(String[] args) {
		EventQueue.invokeLater(new Runnable() {
			public void run() {
				try {
					Programmin01 frame = new Programmin01();
					frame.setVisible(true);
				} catch (Exception e) {
					e.printStackTrace();}}});}
	public Programmin01() {
		initialize();}
	private void initialize() {
		setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
		setBounds(100, 100, 294, 135);
		contentPane = new JPanel();
		contentPane.setBorder(new EmptyBorder(5, 5, 5, 5));
		setContentPane(contentPane);
		setTitle("마일을 킬로미터로 변환");
		contentPane.setLayout(new FlowLayout(FlowLayout.CENTER, 5, 5));
		
		panel = new Programming01_panel();
		contentPane.add(panel);
		
		btnNewButton = new JButton("변환");
		contentPane.add(btnNewButton);
		btnNewButton.addActionListener(this);
		
		Result = new JTextField(20);
		contentPane.add(Result);
	}

	public void actionPerformed(ActionEvent e) {
		if(e.getActionCommand().equals("변환")){
			int distance=0;
			try{
				distance=Integer.parseInt(panel.getTextField().trim());
			}catch(NumberFormatException err){
				JOptionPane.showMessageDialog(this, "숫자만 가능합니다");
				panel.setTextField("");
		}Result.setText(distance*1.609+""+"킬로미터입니다");
	}
}
}